//package com.hz.ruoyilgorder.config;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.actuate.health.Health;
//import org.springframework.boot.actuate.health.HealthIndicator;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.sql.DataSource;
//import java.sql.Connection;
//import java.sql.SQLException;
//
//@Configuration
//public class CustomDataSourceHealthConfig {
//
//    @Value("${spring.datasource.dbcp2.validation-query:select 1}")
//    private String defaultQuery;
//
//    @Bean
//    public HealthIndicator dataSourceHealthIndicator(DataSource dataSource) {
//        return () -> {
//            try (Connection connection = dataSource.getConnection()) {
//                if (connection.isValid(1)) {
//                    return Health.up().withDetail("database", "connected").build();
//                } else {
//                    return Health.down().withDetail("database", "not connected").build();
//                }
//            } catch (SQLException e) {
//                return Health.down(e).withDetail("database", "not connected").build();
//            }
//        };
//    }
//}
